package com.ruoyi.web.controller.lucky;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lucky.domain.TRedBag;
import com.ruoyi.lucky.service.ITRedBagService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 口令红包Controller
 * 
 * @author liuhongbin
 * @date 2020-11-24
 */
@Controller
@RequestMapping("/lucky/bag")
public class TRedBagController extends BaseController
{
    private String prefix = "lucky/bag";

    @Autowired
    private ITRedBagService tRedBagService;

    @RequiresPermissions("lucky:bag:view")
    @GetMapping()
    public String bag()
    {
        return prefix + "/bag";
    }

    /**
     * 查询口令红包列表
     */
    @RequiresPermissions("lucky:bag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRedBag tRedBag)
    {
        startPage();
        List<TRedBag> list = tRedBagService.selectTRedBagList(tRedBag);
        return getDataTable(list);
    }

    /**
     * 导出口令红包列表
     */
    @RequiresPermissions("lucky:bag:export")
    @Log(title = "口令红包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRedBag tRedBag)
    {
        List<TRedBag> list = tRedBagService.selectTRedBagList(tRedBag);
        ExcelUtil<TRedBag> util = new ExcelUtil<TRedBag>(TRedBag.class);
        return util.exportExcel(list, "bag");
    }

    /**
     * 新增口令红包
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存口令红包
     */
    @RequiresPermissions("lucky:bag:add")
    @Log(title = "口令红包", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRedBag tRedBag)
    {
        return toAjax(tRedBagService.insertTRedBag(tRedBag));
    }

    /**
     * 修改口令红包
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TRedBag tRedBag = tRedBagService.selectTRedBagById(id);
        mmap.put("tRedBag", tRedBag);
        return prefix + "/edit";
    }

    /**
     * 修改保存口令红包
     */
    @RequiresPermissions("lucky:bag:edit")
    @Log(title = "口令红包", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRedBag tRedBag)
    {
        return toAjax(tRedBagService.updateTRedBag(tRedBag));
    }

    /**
     * 删除口令红包
     */
    @RequiresPermissions("lucky:bag:remove")
    @Log(title = "口令红包", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tRedBagService.deleteTRedBagByIds(ids));
    }

    /**
     * 领取详情
     */
    @GetMapping("/bagInfo")
    public String bagInfo(ModelMap mmap, Long bagId) {
        mmap.put("bagId", bagId);
        return "lucky/open/openInfo";
    }

}
